package com.wannengbang.cloudleader.login.model;


import com.wannengbang.cloudleader.MyApplication;
import com.wannengbang.cloudleader.appconst.MethodType;
import com.wannengbang.cloudleader.appconst.URLConst;
import com.wannengbang.cloudleader.base.DataCallBack;
import com.wannengbang.cloudleader.bean.BaseResponseBean;
import com.wannengbang.cloudleader.bean.LoginBean;
import com.wannengbang.cloudleader.retorfit_manager.ResponseObserver;
import com.wannengbang.cloudleader.retorfit_manager.RetrofitHelper;
import com.wannengbang.cloudleader.utils.ToastUtil;

import java.util.HashMap;
import java.util.Map;

/**
 * 登录
 */

public class LoginModelImpl implements ILoginModel {


    @Override
    public void requestLoginByPwd(String mobile, String password, String client_no, DataCallBack<LoginBean> callBack) {
        Map<String, Object> params = new HashMap<>();
        params.put("client_no", client_no == null ? "" : client_no);
        params.put("mobile", mobile);
        params.put("password", password);
        params.put("oem_no", MyApplication.getOem_no());
        RetrofitHelper.getInstance().request(MethodType.POST, URLConst.LOGIN, params, new ResponseObserver<LoginBean>() {
            @Override
            public void onSuccessful(LoginBean bean, String msg) {
                callBack.onSuccessful(bean);
            }

            @Override
            public void onFailure(LoginBean bean, String msg, String code) {
                ToastUtil.showShort(msg);
            }
        });
    }

    @Override
    public void requestSendVerifyCode(String mobile, String type, DataCallBack<BaseResponseBean> callBack) {
        Map<String, Object> params = new HashMap<>();
        params.put("mobile", mobile);
        params.put("type", type);
        params.put("oem_no", MyApplication.getOem_no());
        RetrofitHelper.getInstance().request(MethodType.POST, URLConst.SENDVERIFYCODE, params, new ResponseObserver<BaseResponseBean>() {
            @Override
            public void onSuccessful(BaseResponseBean bean, String msg) {
                callBack.onSuccessful(bean);
            }

            @Override
            public void onFailure(BaseResponseBean bean, String msg, String code) {
                ToastUtil.showShort(msg);
            }
        });

    }

    @Override
    public void requestForgetPassword(String mobile, String code, String password, String type, DataCallBack<BaseResponseBean> callBack) {
        Map<String, Object> params = new HashMap<>();
        params.put("mobile", mobile);
        params.put("code", code);
        params.put("password", password);
        params.put("type", type);
        params.put("oem_no", MyApplication.getOem_no());
        RetrofitHelper.getInstance().request(MethodType.POST, URLConst.FORGETPASSWORD, params, new ResponseObserver<BaseResponseBean>() {
            @Override
            public void onSuccessful(BaseResponseBean bean, String msg) {
                callBack.onSuccessful(bean);
            }

            @Override
            public void onFailure(BaseResponseBean bean, String msg, String code) {
                ToastUtil.showShort(msg);
            }
        });
    }

    @Override
    public void requestEditMobile(String mobile, String code, String password, DataCallBack<BaseResponseBean> callBack) {
        Map<String, Object> params = new HashMap<>();
        params.put("mobile", mobile);
        params.put("code", code);
        params.put("password", password);
        RetrofitHelper.getInstance().request(MethodType.POST, URLConst.editMobile, params, new ResponseObserver<BaseResponseBean>() {
            @Override
            public void onSuccessful(BaseResponseBean bean, String msg) {
                callBack.onSuccessful(bean);
            }

            @Override
            public void onFailure(BaseResponseBean bean, String msg, String code) {
                ToastUtil.showShort(msg);
            }
        });
    }
}
